/**
 * 中央装盘
 */
class Middle extends eui.Component {
	public group_0: eui.Group;
	public group_1: eui.Group;
	public group_2: eui.Group;
	public group_3: eui.Group;
	public clockLabel: eui.BitmapLabel;

	public constructor() {
		super();
		this.skinName = "MiddleSkin";
	}

	public childrenCreated(): void {}
	/**
	 * 显示高亮
	 */
	public showLight(tag: number): void {
		for (var i = 0; i < 4; i++) {
			(this["group_" + i] as eui.Group).visible = false;
		}
		(this["group_" + tag] as eui.Group).visible = true;
		this.clockRun();
	}

	/**
	 * 角度旋转
	 */
	public setRotation(chairId: number): void {
		this.rotation = chairId * 90;
		this.clockLabel.rotation = -chairId * 90;
	}
	private effect: egret.SoundChannel;
	/**计时开始 */
	public clockRun(): void {
		var self = this;
		var time = 10;
		this.clockLabel.visible = true;
		egret.Tween.removeTweens(self.clockLabel);
		var loop = function () {
			egret.Tween.get(self.clockLabel).call(() => {
				time--;
				self.clockLabel.text = time + "";
				if (time == 3) {
					self.effect = how.SoundManager.playSound("timeup_alarm_mp3");
				}
				if (time == 0) {
					time = 10;
					// self.clockLabel.visible = false;
				}
			}, self).wait(1000).call(loop);
		};
		loop();
	}

	public clear(): void {
		this.clockLabel.text = "10";
		egret.Tween.removeTweens(this.clockLabel);
	}

	public stopEffect(): void {
		if (this.effect) {
			this.effect.stop();
			this.effect = null;
		}
	}

}